package com.example.coffeejava.Service.Impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.coffeejava.Dto.CountDto;
import com.example.coffeejava.Dto.PriceDto;
import com.example.coffeejava.Dto.Result;
import com.example.coffeejava.Entity.Info;
import com.example.coffeejava.Entity.Shop;
import com.example.coffeejava.Entity.UserHolder;
import com.example.coffeejava.Mapper.OrderMapper;
import com.example.coffeejava.Mapper.ShopMapper;
import com.example.coffeejava.Service.InfoService;
import com.example.coffeejava.Service.ShopService;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ShopServiceImpl extends ServiceImpl<ShopMapper, Shop> implements ShopService {
    @Resource
    private OrderMapper orderMapper;
@Resource
private InfoService infoService;
    public Result getcount() {
        Map<String, Integer> map = new HashMap<>();
        Integer curtotalprice = orderMapper.getcurcount(UserHolder.getUser().getId());
        Integer curtotalCount = orderMapper.getcurtcount(UserHolder.getUser().getId());
        Integer alltotalprice = orderMapper.gettotalprice(UserHolder.getUser().getId());
        Integer alltotalCount = orderMapper.gettotalcount(UserHolder.getUser().getId());
        map.put("curtotalprice", curtotalprice);
        map.put("curtotalCount", curtotalCount);
        map.put("alltotalprice", alltotalprice);
        map.put("alltotalCount", alltotalCount);
        System.out.println(map);
        return Result.ok(map);

    }

    public Result chart() {

//        List<PriceDto> list=orderMapper.getprice(UserHolder.getUser().getId());
//        System.out.println(list);
        return Result.ok(orderMapper.getprice(UserHolder.getUser().getId()));
    }
    public Result chart2(){
        List<CountDto> list=new ArrayList<>();
        List<Info> list1=infoService.list();
        for (Info info:list1){
            CountDto countDto=new CountDto();
            countDto.setName(info.getName());
            Integer ids= Math.toIntExact(info.getId());

            countDto.setCount(orderMapper.getcount2(ids,UserHolder.getUser().getId()));
       list.add(countDto);
        }
        return Result.ok(list);
//        return Result.ok(orderMapper.getcount(UserHolder.getUser().getId()));
    }
}
